/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import entity.Pessoa;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.persistence.Query;
import javax.swing.JOptionPane;

/**
 *
 * @author Thiago
 */
public class PessoaDAO extends EntityDAO<Pessoa> {

    public List<Pessoa> listar() {
        try {
            transaction.begin();
            Query query = en.createNamedQuery("Pessoa.findAll");
            List<Pessoa> lista = query.getResultList();
            transaction.commit();
            return lista;

        } catch (Exception e) {
            transaction.rollback();
            JOptionPane.showMessageDialog(null, e.getMessage());
        }
        return null;
    }

    public List<Pessoa> listar(String nome) {
        try {
            transaction.begin();
            Query query = en.createNamedQuery("Pessoa.getByPessoaNome");
            List<Pessoa> lista = query.getResultList();
            transaction.commit();
            return lista;

        } catch (Exception e) {
            transaction.rollback();
            JOptionPane.showMessageDialog(null, e.getMessage());
        }

        return null;
    }
}
